home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / v cisle / htttrack / httrack-3.41-3.exe / {app} / libtest / callbacks-example-filenameiisbug.c < prev    next >
C/C++ Source or Header  |  2006-06-04  |  2KB  |  67 lines

  1. /*
  2.     HTTrack external callbacks example : changing folder names ending with ".com"
  3.     with ".c0m" as a workaround of IIS bug (see KB 275601)
  4.  
  5.     How to build: (callback.so or callback.dll)
  6.       With GNU-GCC:
  7.         gcc -O -g3 -Wall -D_REENTRANT -shared -o mycallback.so callbacks-example.c -lhttrack1
  8.       With MS-Visual C++:
  9.         cl -LD -nologo -W3 -Zi -Zp4 -DWIN32 -Fe"mycallback.dll" callbacks-example.c libhttrack1.lib
  10.  
  11.       Note: the httrack library linker option is only necessary when using libhttrack's functions inside the callback
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17.  
  18. /* Standard httrack module includes */
  19. #include "httrack-library.h"
  20. #include "htsopt.h"
  21. #include "htsdefines.h"
  22.  
  23. /* Function definitions */
  24. static int mysavename(t_hts_callbackarg *carg, httrackp *opt, const char* adr_complete, const char* fil_complete, const char* referer_adr, const char* referer_fil, char* save);
  25.  
  26. /* 
  27. module entry point 
  28. */
  29. EXTERNAL_FUNCTION int hts_plug(httrackp *opt, const char* argv) {
  30.   const char *arg = strchr(argv, ',');
  31.   if (arg != NULL)
  32.     arg++;
  33.   CHAIN_FUNCTION(opt, savename, mysavename, NULL);
  34.   return 1;  /* success */
  35. }
  36.  
  37. /*
  38.   Replaces all "offending" IIS extensions (exe, dll..) with "nice" ones
  39. */
  40. static int mysavename(t_hts_callbackarg *carg, httrackp *opt, const char* adr_complete, const char* fil_complete, const char* referer_adr, const char* referer_fil, char* save) {
  41.   static const char* iisBogus[]        = { ".com", ".exe", ".dll", ".sh", NULL };
  42.   static const char* iisBogusReplace[] = { ".c0m", ".ex3", ".dl1", ".5h", NULL }; /* MUST be the same sizes */
  43.   char* a;
  44.  
  45.   /* Call parent functions if multiple callbacks are chained. */
  46.   if (CALLBACKARG_PREV_FUN(carg, savename) != NULL) {
  47.     if (!CALLBACKARG_PREV_FUN(carg, savename)(CALLBACKARG_PREV_CARG(carg), opt, adr_complete, fil_complete, referer_adr, referer_fil, save)) {
  48.       return 0;  /* Abort */
  49.     }
  50.   }
  51.  
  52.   /* Process */
  53.   for(a = save ; *a != '\0' ; a++) {
  54.     int i;
  55.     for(i = 0 ; iisBogus[i] != NULL ; i++) {
  56.       int j;
  57.       for(j = 0 ; iisBogus[i][j] == a[j] && iisBogus[i][j] != '\0' ; j++);
  58.       if (iisBogus[i][j] == '\0' && ( a[j] == '\0' || a[j] == '/' || a[j] == '\\' ) ) {
  59.         strncpy(a, iisBogusReplace[i], strlen(iisBogusReplace[i]));
  60.         break;
  61.       }
  62.     }
  63.   }
  64.  
  65.   return 1;  /* success */
  66. }
  67.